package com.demo.petshop.controller;

import com.demo.petshop.entity.VideoUploadDTO;
import com.demo.petshop.entity.Videos;
import com.demo.petshop.service.VideosService;
import com.demo.petshop.util.Result;
import com.mybatisflex.core.paginate.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 *  控制层。
 *
 * @author lenovo
 * @since 2025-06-11
 */
@RestController
@RequestMapping("/videos")
public class VideosController {

    @Autowired
    private VideosService videosService;

    @PostMapping("save")
    public boolean save(@RequestBody Videos videos) {
        return videosService.save(videos);
    }

    @DeleteMapping("remove/{id}")
    public boolean remove(@PathVariable Serializable id) {
        return videosService.removeById(id);
    }

    @PostMapping("update")
    public Object update(@RequestBody Videos videos) {
        return Result.success(videosService.updateById(videos));
    }

    @GetMapping("/tags")
    public Object getTags(){
        return videosService.getTags();
    }

    /**
     * 查询所有。
     *
     * @return 所有数据
     */
    @GetMapping("list")
    public List<Videos> list() {
        return videosService.list();
    }

    /**
     * 根据主键获取详细信息。
     *
     * @param id 主键
     * @return 详情
     */
    @GetMapping("getInfo/{id}")
    public Videos getInfo(@PathVariable Serializable id) {
        return videosService.getById(id);
    }

    /**
     * 分页查询。
     *
     * @param page 分页对象
     * @return 分页对象
     */
    @GetMapping("page")
    public Page<Videos> page(Page<Videos> page) {
        return videosService.page(page);
    }

    @GetMapping("categories")
    public Object getCategories(){
        return videosService.getCategories();
    }

    @PostMapping("list")
    public Object getList(@RequestBody Map<String, Object> params){
        return videosService.getList(params);
    }

    @GetMapping("listStore")
    public Object listStore(@RequestParam Integer storeId){
        return videosService.listStore(storeId);
    }

    @PostMapping("updateProducts")
    public Object updateProducts(@RequestBody Map<String, Object> params){
        return videosService.updateProducts(params);
    }

    @PostMapping("/upload")
    public Object uploadVideo(@RequestBody VideoUploadDTO videoUploadDTO) {
        // 注意：这里使用了 @RequestBody 注解
        return videosService.uploadVideo(videoUploadDTO);
    }

    @GetMapping("video")
    public Object getVideo(@RequestParam Integer videoId){
        return videosService.getVideo(videoId);
    }

    @GetMapping("comments")
    public Object getComments(@RequestParam Integer videoId){
        return videosService.getComments(videoId);
    }

    @GetMapping("recommended")
    public Object getRecommended(@RequestParam Integer videoId){
        return videosService.getRecommended(videoId);
    }

    @GetMapping("addViewer")
    public Object addViewer(@RequestParam Integer videoId){
        return videosService.addViewer(videoId);
    }

    @GetMapping("/delete")
    public Object delete(@RequestParam Integer videoId) {
        return videosService.delete(videoId);
    }

    @GetMapping("/listByMemberLevel")
    public Object listByMemberLevel(){
        return videosService.listByMemberLevel();
    }
}
